package com.topInterview;

import java.util.Stack;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/19 15:31
 */
public class Leecode20_ValidParentheses {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c == '(' || c == '[' || c == '{') {
                stack.push(c);
            } else {
                Character push = stack.pop();
                Character v = isV(push);
                if (c != v) {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }


    public Character isV(Character s) {
        switch (s) {
            case '(':
                return ')';
            case '[':
                return ']';
            case '{':
                return '}';
        }
        return null;
    }

    public static void main(String[] args) {
        String s = "()";
        Leecode20_ValidParentheses leecode20_validParentheses = new Leecode20_ValidParentheses();
        leecode20_validParentheses.isValid(s);
    }
}
